const registerA = document.querySelector('.register-a');
const loginA = document.querySelector('.login-a');
const loginBox = document.querySelector('.login');
const registerBox = document.querySelector('.register');

loginA.addEventListener('click',function(e){
    registerBox.style.display = 'block'
    loginBox.style.display = 'none'
})


registerA.addEventListener('click',function(e){
    loginBox.style.display = 'block';
    registerBox.style.display = 'none';

})


registerBox.querySelector('form').addEventListener('submit',function (e) {
    e.preventDefault()

    const data = $(this).serialize()

    axios.post('/api/register',data)
    .then(result=>{
        console.log(result);

        if(result.data.code===0){
            registerA.click() //模拟点击 敲代码来触发点击事件
        }
    })
})


loginBox.querySelector('form').addEventListener('submit',function (e) {
    e.preventDefault()

    const data = $(this).serialize()

    axios.post('/api/login',data)
    .then(result=>{
        console.log(result);
        if(result.data.code===0){
            localStorage.setItem('token82',result.data.token)
            toastr.success(result.data.message)
            location.href = './index.html'
        }
    })
})